//
//  MainViewController.swift
//  weibo项目
//
//  Created by mac on 16/1/11.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        根控制器的入口
       addChildViewControllers()
//        系统的tabbar是只读属性,是不能被修改的,只能通过KVC的方法来间接修改
        let  mainTabbar = MainTabbar()
        setValue(mainTabbar, forKey: "tabBar")
    }
    
    func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), name: "tabbar_home", title: "首页")
        addChildViewController(MessageTableViewController(), name: "tabbar_message_center", title: "消息")
        addChildViewController(ProfileTableViewController(), name: "tabbar_profile", title: "我")
        addChildViewController(DiscoverTableViewController(), name: "tabbar_discover", title: "发现")
        
    }
    
    func addChildViewController(VC:UIViewController,name:String,title:String) {
//        实例化一个home
//        let home = HomeTableViewController()
//        设置导航控制器的根控制器
          VC.title = title
//        self.tabBar.tintColor = UIColor.orangeColor()
       let nav = UINavigationController(rootViewController: VC)
//        添加控制器
        addChildViewController(nav)
        
//        设置图片
        VC.tabBarItem.image = UIImage(named: name )
//        设置home的title
        
//       VC.tabBarItem.image = UIImage(named: name )?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        VC.tabBarItem.selectedImage = UIImage(named: name + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        VC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
//           home.tabBarItem.title = "首页"
//        home.navigationItem.title = "首页"
        
//        替代设置标题
      
       
        
    }
   
    
}
